#include <iostream>
#include <cstdlib>
#include <getopt.h>
#include "cae_convertor.h"

void printUsage(const char* programName);
int main(int argc, char** argv)
{
    std::string inputFilePath;
    std::string outputFilePath;

    // 定义选项
    static struct option long_options[] = {
        {"input", required_argument, 0, 'i'},
        {"output", required_argument, 0, 'o'},
        {0, 0, 0, 0}
    };

    int opt;
    int option_index = 0;

    // 解析命令行参数
    while ((opt = getopt_long(argc, argv, "i:o:", long_options, &option_index)) != -1) {
        switch (opt) {
            case 'i':
                inputFilePath = optarg;
                break;
            case 'o':
                outputFilePath = optarg;
                break;
            case '?': // 未知选项
                printUsage(argv[0]);
                return 1;
            default:
                printUsage(argv[0]);
                return 1;
        }
    }
        // 检查是否指定了输入和输出文件
    if (inputFilePath.empty() || outputFilePath.empty()) {
        printUsage(argv[0]);
        return 1;
    }

    CaeConvertor().convert(inputFilePath, outputFilePath);
    return 0;
}

void printUsage(const char* programName) {
    std::cerr << "Usage: " << programName << " -i <input_file_path> -o <output_file_path>" << std::endl;
}
